﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DTO
{
    public class GlobalParametersInfo
    {

        //public class Field
        //{
        //    public const string PeriodFrom = "PeriodFrom";
        //    public const string PeriodTo = "PeriodTo";
        //    public const string Tolerance = "Tolerance";

        //}
        //public int PeriodFrom { get; set; }
        //public int PeriodTo { get; set; }
        //public decimal Tolerance { get; set; }
        //public BUDInfo() { }

        //public BUDInfo(System.Data.DataRow dataRow)
        //{
        //    // TODO: Complete member initialization
        //    this.PeriodFrom = Convert.ToInt32(dataRow[Field.PeriodFrom]);
        //    this.PeriodTo = Convert.ToInt32(dataRow[Field.PeriodTo]);
        //    this.Tolerance = Convert.ToDecimal(dataRow[Field.Tolerance]);
        //}
        		#region Local Variable
		public enum Field
		{
			ID,
			DocFolder,
			PeriodFrom,
			PeriodTo,
			Tolerance
		}
		private Int32 _ID;
		private String _DocFolder;
		private Int32 _PeriodFrom;
		private Int32 _PeriodTo;
		private Double _Tolerance;
		
		public Int32 ID{	get{ return _ID;} set{_ID = value;} }
		public String DocFolder{	get{ return _DocFolder;} set{_DocFolder = value;} }
		public Int32 PeriodFrom{	get{ return _PeriodFrom;} set{_PeriodFrom = value;} }
		public Int32 PeriodTo{	get{ return _PeriodTo;} set{_PeriodTo = value;} }
		public Double Tolerance{	get{ return _Tolerance;} set{_Tolerance = value;} }
		
        #endregion LocalVariable
        
        #region Constructor
		public GlobalParametersInfo()
		{
			_ID = 0;
			_DocFolder = "";
			_PeriodFrom = 0;
			_PeriodTo = 0;
			_Tolerance = 0;
		}
		
		public GlobalParametersInfo(
		Int32 ID,
		String DocFolder,
		Int32 PeriodFrom,
		Int32 PeriodTo,
		Double Tolerance
		)
		{
			_ID = ID;
			_DocFolder = DocFolder;
			_PeriodFrom = PeriodFrom;
			_PeriodTo = PeriodTo;
			_Tolerance = Tolerance;
		}
		public GlobalParametersInfo(DataRow dr)
		{
			if (dr != null)
			{
				_ID = dr[Field.ID.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.ID.ToString()]);
				_DocFolder = dr[Field.DocFolder.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.DocFolder.ToString()]);
				_PeriodFrom = dr[Field.PeriodFrom.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.PeriodFrom.ToString()]);
				_PeriodTo = dr[Field.PeriodTo.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.PeriodTo.ToString()]);
				_Tolerance = dr[Field.Tolerance.ToString()] == DBNull.Value?0:Convert.ToDouble(dr[Field.Tolerance.ToString()]);
			}
		}
		public GlobalParametersInfo(DataRowView dr)
		{
			if (dr != null)
			{
				_ID = dr[Field.ID.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.ID.ToString()]);
				_DocFolder = dr[Field.DocFolder.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.DocFolder.ToString()]);
				_PeriodFrom = dr[Field.PeriodFrom.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.PeriodFrom.ToString()]);
				_PeriodTo = dr[Field.PeriodTo.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.PeriodTo.ToString()]);
				_Tolerance = dr[Field.Tolerance.ToString()] == DBNull.Value?0:Convert.ToDouble(dr[Field.Tolerance.ToString()]);
			}
		}
		public GlobalParametersInfo(GlobalParametersInfo objEntr)
		{			
			_ID = objEntr.ID;			
			_DocFolder = objEntr.DocFolder;			
			_PeriodFrom = objEntr.PeriodFrom;			
			_PeriodTo = objEntr.PeriodTo;			
			_Tolerance = objEntr.Tolerance;			
		}
        #endregion Constructor
        
        #region InitTable
		public static DataTable ToDataTable()
		{
			DataTable dt = new DataTable("GlobalParameters");
			dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.ID.ToString(), typeof(Int32)),
				new DataColumn(Field.DocFolder.ToString(), typeof(String)),
				new DataColumn(Field.PeriodFrom.ToString(), typeof(Int32)),
				new DataColumn(Field.PeriodTo.ToString(), typeof(Int32)),
				new DataColumn(Field.Tolerance.ToString(), typeof(Double))
			});
			return dt;
		}
		public DataRow ToDataRow(DataTable dt)
		{
			DataRow row = dt.NewRow();
			row[Field.ID.ToString()] = _ID;
			row[Field.DocFolder.ToString()] = _DocFolder;
			row[Field.PeriodFrom.ToString()] = _PeriodFrom;
			row[Field.PeriodTo.ToString()] = _PeriodTo;
			row[Field.Tolerance.ToString()] = _Tolerance;
			return row;
		}
        #endregion InitTable
    }
}
